<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>新建客户群提醒</title>
	<link rel="stylesheet" href="/layui/css/layui.css">
	<style type="text/css">
		body{
			background: #e9e9e9;
		}
		/*公共头部带搜索*/
		.public_container{
			margin: 20px;
			background: #fff;
		}
		.public_title_container{
			height: 54px;
			padding: 0 20px;
			font-size: 14px;
			display: flex;
			align-items: center;
			background: #f9f9f9;
			border-bottom: 1px solid #f0f0f0;
		}
		/*公共表单部分*/
		.public_form_container{
			padding: 20px 20px 40px 20px;
		}
		.public_form_content{
			padding: 24px 40px 24px 0;
			background: #fff;
			border: 1px solid #e9e9e9;
			margin-bottom: 8px;
		}
		.public_form_List{
			margin-bottom: 10px;
		}
		.public_form_List:last-child{
			margin-bottom: 0px;
		}
		.public_formTitle_container lable{
			font-size: 13px;
			font-weight: bold;
		}
		.newcreatGroup_otherTips_container{
			color: #999;
			font-size: 14px;
			padding-top: 10px;
		}
		.table-stop{
			text-align: center;
			cursor: pointer;
			color: #2196f3;
			margin-top: 10px;
		}
		.table-input{
			height: 38px;
			line-height: 1.3;
			border-width: 1px;
			border-style: solid;
			background-color: #fff;
			border-radius: 2px;
			border-color: #e6e6e6;
			padding-left: 10px;
			margin: 10px;
			width: 70px;
		}

	</style>
</head>
<body>

	<form class="layui-form" id="form1">
		

		<div class="public_container">
			<!-- /*公共头部带搜索*/ -->
			<div class="public_content">
				<div class="public_title_container">
					<p>客户群提醒</p>
				</div>

			</div>
			<!-- /*公共头部带搜索*/ end -->
			<!-- 公共表单部分 -->
			<div class="public_form_container">
				<div class="public_form_content">
					<div class="public_form_List">
						<div class="public_formTitle_container">
							<lable class="layui-form-label">方案名称：</lable>
						</div>
						<div class="public_formOther_container">
							<div class="layui-input-block">
								<input type="text" name="name" value="{$remind->name }" required  lay-verify="required" placeholder="请输入任务名称" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
				</div>

				
				<div class="public_form_content">
					
					<div class="public_form_List">
						<div class="public_formTitle_container">
							<lable class="layui-form-label">群聊：</lable>
						</div>
						<div class="public_formOther_container">
							<div class="layui-input-block">
								<span class="layui-btn layui-btn-primary" id="addGroup">+ 选择群聊</span>
							</div>
							<div class="layui-input-block newcreatGroup_otherTips_container" id="groupChatCon">
								{loop $remind->chat as $chat}
									<span class="layui-btn layui-btn-primary">
										{$chat->name }
										<input type="hidden" name="chatid[]" value="{$chat->chat_id }">
										<input type="hidden" name="item.chatid[]" value="{$chat->chat_id }">
									</span>
								{/loop}

							</div>

						</div>
					</div>

				</div>

				<div class="public_form_content">
					<div class="public_form_List">
						<div class="public_formTitle_container">
							<lable class="layui-form-label">行为提醒：</lable>
						</div>
						<div class="public_formOther_container">
							<div class="layui-input-block">
								<input type="checkbox" name="img_qrcode" value="1" title="发送带二维码图片" lay-skin="primary" {if $remind->img_qrcode} checked {/if} >
							</div>
							<div class="layui-input-block" >
								<input type="checkbox" name="link" value="1" title="发送链接分享" lay-skin="primary" {if $remind->link} checked {/if}>
							</div>
							<div class="layui-input-block" >
								<input type="checkbox" name="weapp" value="1" title="发送小程序" lay-skin="primary" {if $remind->weapp} checked {/if}>
							</div>
							<div class="layui-input-block" >
								<input type="checkbox" name="card" value="1" title="发送名片" lay-skin="primary" {if $remind->card} checked {/if}>
							</div>
							<div class="layui-input-block">
								<input type="checkbox" id="text_key" name="text_key" value="1" lay-filter="text_key" title="聊天消息中包含以下关键字" lay-skin="primary" {if $remind->text_key} checked {/if}>
								<div id="keys_div" style="margin-top: 20px;display: none" >
									<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="show_key_input();">添加</button>

									<div class="layui-input-inline" id="div_input" style="display: none">
										<input type="text" id="keys_input" name="keys_input" class="layui-input" style="height: 30px;" placeholder="输入后回车">
									</div>

									<div class="layui-btn-container" style="margin-top: 10px" id="key_item_div">
										{loop $remind->key_list as $key}
										<div class="layui-btn-group">
											<span class="layui-btn layui-btn-primary layui-btn-sm">{$key }</span>
											<span class="layui-btn layui-btn-primary layui-btn-sm" onclick="del_key(this);"><i class="layui-icon">&#xe640;</i></span>
											<input type="hidden" name="keys[]" value="{$key }" >
										</div>
										{/loop}

									</div>

								</div>
							</div>

						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-input-block">
						<a class="layui-btn" lay-submit lay-filter="formDemo">立即提交</a>
						<!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
					</div>
				</div>
			</div>
			<!-- 公共表单部分 end-->
		</div>
	</form>
	<script src="/cdn/jquery.js"></script>
	<script src="/layui/layui.js"></script>
	<script src="/js/ajax.js"></script>
	<script type="text/javascript">
		
		// 弹窗
		layui.use('layer', function(){
		  var layer = layui.layer;
		}); 
		// 表单
		layui.use('form', function(){
		  var form = layui.form;

		  //监听提交
		  form.on('submit(formDemo)', function(data){
		    //layer.msg(JSON.stringify(data.field));
		    //return false;
			var formData = $('#form1').serialize();

			myAjaxPost(false, true, '', formData, function (resp) {
				if (resp.status == 'success') {
					tusi(resp.msg);
					setTimeout(function(){
						location.href = 'group_remind_list.html';
					},2000);
				}else{
					alert(resp.msg);
				}
			});
		  });


			form.on('checkbox(text_key)', function(data){
				if(data.elem.checked){
					$("#keys_div").show();
				}else{
					$("#keys_div").hide();
				}
			});
		});
		
	</script>
	<script type="text/javascript">
		//判断 关键词显示
		var key_flag = '{$remind->text_key}';
		if(key_flag){
			$("#keys_div").show();
		}else{
			$("#keys_div").hide();
		}

		$('#addGroup').on('click',function(){
			layer.open({
			  type: 2,
			  title: '请选择群聊',
			  shadeClose: true,
			  shade: 0.2,
			  area: ['700px', '530px'],
			  content: 'select_group_chat2.html'
			}); 
		})
	</script>
	
	<script>
	layui.use(['element', 'layer', 'upload'], function () {
	  var layer = layui.layer;
	});

	

	function delitem(a){
		$(a).parents('tr.groupItems').remove();
	}

	function groupItemsData(result){
		var htmlt = "";
		var data = result.data;
		for (var i = 0;i<data.length;i++) {
			htmlt += '<span class="layui-btn layui-btn-primary">';
			htmlt += data[i].name;
			htmlt += '<input type="hidden" name="chatid[]" value="'+ data[i].chat_id +'">';
			htmlt += '<input type="hidden" name="item.chatid[]" value="'+ data[i].chat_id +'">';
			htmlt += '</span>';
		}
		$("#groupChatCon").append(htmlt);
	}

	function del_key(a){
		$(a).parent().remove();
	}
	function show_key_input(){
		$("#div_input").show();
	}

	$("input[name='keys_input']").keydown(function(e){
		var curKey = e.which;
		if (curKey == 13) {
			//按回车键 添加key item
			var val = $(this).val();
			var html = "";
			html +=  '<div class="layui-btn-group">';
			html +=  '<span class="layui-btn layui-btn-primary layui-btn-sm">'+val+'</span>';
			html +=  '<span class="layui-btn layui-btn-primary layui-btn-sm" onclick="del_key(this);"><i class="layui-icon">&#xe640;</i></span>';
			html +=  '<input type="hidden" name="keys[]" value="'+val+'" >';
			html +=  '</div>';
			$("#key_item_div").append(html)
			//追加完成后  清空  隐藏
			$(this).val("");
			$(this).parent().hide();
		}
	});

	</script>
</body>
</html>